﻿@model KL.Store.Web.Models.AddToWishListModel
@using KL.Store.Core
@{
    Layout = null;
}
@{var qty = new List<SelectListItem> {
                new SelectListItem {Text = "1", Value = "1"},
                new SelectListItem {Text = "2", Value = "2"},
                new SelectListItem {Text = "3", Value = "3"},
                new SelectListItem {Text = "4", Value = "4"},
                new SelectListItem {Text = "5", Value = "5"},
                new SelectListItem {Text = "6", Value = "6"},
                new SelectListItem {Text = "7", Value = "7"},
                new SelectListItem {Text = "8", Value = "8"},
                new SelectListItem {Text = "9", Value = "9"},
                new SelectListItem {Text = "1O", Value = "10"}
              };
}
@using (Ajax.BeginForm("Set", "WishList", new { }, new AjaxOptions { UpdateTargetId = "MessageDlg", HttpMethod = "Post", LoadingElementId = "Loading" }, new { id = "frmSet", name = "frmSet", style = "width:100%" }))
{
    @Html.HiddenFor(model => model.ProductId)
    @Html.HiddenFor(model => model.SelectedList)
    @Html.HiddenFor(model => model.SelectedListChecked)
    <table>
        <tr valign="top">
            <td align="center" style="width: 200px">
                <img src="@(Parameters.WebSiteImageUrl)/product-small/@(Model.ProductId.ToString())_1.jpg" alt="@(Model.ProductName.Replace("\"", ""))" /><br />
                @Html.DisplayFor(model => model.ProductId)<br />
                @Html.DisplayFor(model => model.ProductName)<br />
                <br />
                @Html.DropDownListFor(model => model.Qty, qty, new { @style = "width:55px" })
            </td>
            <td>
                @foreach (var item in Model.WishLists)
                {
                    if (!item.HasProcess)
                    { 
                    <input name="cbSelected" type="checkbox" value="@item.ListId" @(item.Selected ? "Checked" : "") onchange="submitSelected(this, @item.ListId);"/>@(item.ListName)                     
                    }
                    else
                    {
                    <input name="cbSelected" type="checkbox" value="@item.ListId" @(item.Selected ? "Checked" : "") onchange="submitSelected(this, @item.ListId);" disabled="disabled"/>@item.ListName<text> - İşlem Görmüş</text>
                    }
                    <br />
                }
            </td>
        </tr>
    </table>
    <div id="MessageDlg">
    </div>    
}
<script type="text/javascript">
    function submitSelected(cb, i) {
        try {
            $('#SelectedList').val(i);
            $('#SelectedListChecked').val($(cb).is(':checked'));
            $('#frmSet').submit();
        }
        catch (Err) {
            alert("Hata!!!");
            $('#MessageDlg').html("<font color='Red'>Hata oluştu tekrar deneyiniz!</font>");
        }
    };
</script>
